<?php
/**
 * @filename DuckSimulator.php
 * @author LD King
 * @encoding UTF-8
 * @date 2008-9-19 | 下午03:33:28
 * @package 12-MVC
 * @subpackage 
 * @usage 鸭子模拟器
 * @note 产生一些鸭子，确认鸭子会呱呱叫
 * @copyright Copyright (c) 2007 - 2008 LD (http://mifunny.info)
 * @version $Id: $
 */

include_once 'Quackable.php';
include_once 'Goose.php';

/**
 * 这里是工厂方法
 */
include_once 'AbstractDuckFactory.php';

/**
 * 加入装饰者， 计算鸭子的叫声
 */
include_once 'QuackCounter.php';

/**
 * 这个复合模式
 */
include_once 'Flock.php';


/**
 * 鸭子模拟器
 *
 */
class DuckSimlator {
	
	/**
	 * 产生鸭子……
	 *
	 */
	public function simlate(AbstractDuckFactory $duckFactory) {
/*		$mallardDuck = new MallardDuck();
		$redheadDuck = new RedheadDuck();
		$duckCall = new DuckCall();
		$rubberDuck = new RubberDuck();*/
		
/*		$mallardDuck = new QuackCounter(new MallardDuck());
		$redheadDuck = new QuackCounter(new RedheadDuck());
		$duckCall = new QuackCounter(new DuckCall());
		$rubberDuck = new QuackCounter(new RubberDuck());*/

		$redheadDuck = $duckFactory->createRedheadDuck();
		$duckCall = $duckFactory->createDuckCall();
		$rubberDuck = $duckFactory->createRubberDuck();
		
		/**
		 * 鹅的适配器
		 */
		//$goose = new GooseAdapter(new Goose());
		$goose = $duckFactory->createGoose();
		
		//echo "<br />Duck Simlator!<hr /><br />";
		echo "<br />Duck Simlator: With Composite ── Flocks.<hr /><br />";
		
		$flockOfDucks = new Flock();
		$flockOfDucks->add($redheadDuck);
		$flockOfDucks->add($duckCall);
		$flockOfDucks->add($rubberDuck);
		$flockOfDucks->add($goose);
		
		/**
		 * 野鸭群
		 */
		$flockOfMallardDucks = new Flock();
		
		$mallardDuckOne = $duckFactory->createMallardDuck();
		$mallardDuckTwo = $duckFactory->createMallardDuck();
		$mallardDuckThree = $duckFactory->createMallardDuck();
		$mallardDuckFour = $duckFactory->createMallardDuck();
		
		$flockOfMallardDucks->add($mallardDuckOne);
		$flockOfMallardDucks->add($mallardDuckTwo);
		$flockOfMallardDucks->add($mallardDuckThree);
		$flockOfMallardDucks->add($mallardDuckFour);
		
		/**
		 * 把野鸭群加入主集合
		 */
		$flockOfDucks->add($flockOfMallardDucks);
		
		echo "<br />Duck Simulator: Whole Flock Simulation.<br />";
		$this->simlator($flockOfDucks);
		
		echo "<br />Duck Simulator: Mallard Flock Simulation.<br />";
		$this->simlator($flockOfMallardDucks);
		
		
		/*$this->simlator($mallardDuck);
		$this->simlator($redheadDuck);
		$this->simlator($duckCall);
		$this->simlator($rubberDuck);
	
		$this->simlator($goose);*/
		
		echo "<br />The ducks quacked ".QuackCounter::getQuacks()." times.<br />";
	}
	
	/**
	 * 重载simlate方法，行不？？？ 不行！！！
	 *
	 * @param Quackable $duck
	 */
	public function simlator(Quackable $duck) {
		$duck->quack();
	}
} /* END class DuckSimlator */

$duckSimlator = new DuckSimlator();
$duckFactory = new CountingDuckFactory();
$duckSimlator->simlate($duckFactory);

?>